package org.come.lianhua;

import com.tool.tcpimg.UIUtils;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class AutoMaticRefiningJframe extends JInternalFrame implements MouseListener
{
    private int first_x;
    private int first_y;
    private AutoMaticRefiningJpanel assistantJpanel;

    public static AutoMaticRefiningJframe getAssistantJframe() {
        return (AutoMaticRefiningJframe)FormsManagement.getInternalForm(999).getFrame();
    }

    public AutoMaticRefiningJframe() throws Exception {
        this.assistantJpanel = new AutoMaticRefiningJpanel();
        this.getContentPane().add((Component)this.assistantJpanel);
        this.setBorder(BorderFactory.createEmptyBorder());
        ((BasicInternalFrameUI)this.getUI()).setNorthPane(null);
        this.setBounds(300, 200, 416, 516);
        this.pack();
        this.setDefaultCloseOperation(3);
        this.setVisible(false);
        this.setBackground(UIUtils.Color_BACK);
        this.addMouseMotionListener(new MouseMotionListener() {
            @Override
            public void mouseMoved(final MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(final MouseEvent e) {
                if (AutoMaticRefiningJframe.getAssistantJframe().isVisible()) {
                    final int x = e.getX() - AutoMaticRefiningJframe.this.first_x;
                    final int y = e.getY() - AutoMaticRefiningJframe.this.first_y;
                    AutoMaticRefiningJframe.getAssistantJframe().setBounds(x + AutoMaticRefiningJframe.getAssistantJframe().getX(), y + AutoMaticRefiningJframe.getAssistantJframe().getY(), AutoMaticRefiningJframe.getAssistantJframe().getWidth(), AutoMaticRefiningJframe.getAssistantJframe().getHeight());
                }
            }
        });
        this.addMouseListener((MouseListener)this);
    }

    @Override
    public void mouseClicked(final MouseEvent e) {
    }

    @Override
    public void mousePressed(final MouseEvent e) {
        Music.addyinxiao("关闭窗口.mp3");
        if (e.isMetaDown()) {
            FormsManagement.HideForm(999);
            FormsManagement.disposeForm(999);
        }
        else {
            FormsManagement.Switchinglevel(999);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();
    }

    @Override
    public void mouseReleased(final MouseEvent e) {
    }

    @Override
    public void mouseEntered(final MouseEvent e) {
    }

    @Override
    public void mouseExited(final MouseEvent e) {
    }

    public int getFirst_x() {
        return this.first_x;
    }

    public void setFirst_x(final int first_x) {
        this.first_x = first_x;
    }

    public int getFirst_y() {
        return this.first_y;
    }

    public void setFirst_y(final int first_y) {
        this.first_y = first_y;
    }

    public AutoMaticRefiningJpanel getAssistantJpanel() {
        return assistantJpanel;
    }

    public void setAssistantJpanel(AutoMaticRefiningJpanel assistantJpanel) {
        this.assistantJpanel = assistantJpanel;
    }
}
